install.packages("zTree")
require(zTree)

#Load in some Data
zTT1= zTreeTables("January20spillovers.xls")
subjects1=zTT1$subjects
subjects1$Subject=subjects1$Subject+100

zTT2= zTreeTables("January21spillovers.xls")
subjects2=zTT2$subjects
subjects2$Subject=subjects2$Subject+200

subjects=rbind(subjects1,subjects2,subjects3)

#Clean data
subjects$responder=(subjects$"response1[50]">0)
subjects=subset(subjects,responder>0)

uidlist=unique(subjects$Subject)



#create a frame with observations
obsframe=data.frame(uid=vector('numeric'),Bcorrinc=vector('numeric'),Bfailinc=vector('numeric'),group=vector('numeric'),cpresent=vector('numeric'),block=vector('numeric'), number=vector('numeric'), state=vector('numeric'), response=vector('numeric'))
for(i in 1:length(uidlist)){
playframe=subjects[i,]
uidplace=uidlist[i]

groupplace=as.numeric(playframe[11])

#Properly assign parameters to different experiment types
if(groupplace==1){
Bcorrincplace=55
Bfailincplace=40
}

if(groupplace==2){
Bcorrincplace=52
Bfailincplace=40
}

if(groupplace==3){
Bcorrincplace=52
Bfailincplace=30
}

if(groupplace==4){
Bcorrincplace=55
Bfailincplace=30
}

#block 1
for (j in 1:50){
blockplace=1
cpresentplace=(playframe$"blockord[1]"==2)
numberplace=j
stateplace=playframe[1,(745+j)]
responseplace=playframe[1,(82+j)]
addframe=data.frame(uid=uidplace,Bcorrinc=Bcorrincplace,Bfailinc=Bfailincplace,group=groupplace,cpresent=cpresentplace,block=blockplace, number=numberplace, state=stateplace, response=responseplace)
obsframe=rbind(obsframe,addframe)
}

#block 2
for (j in 1:50){
blockplace=2
cpresentplace=(playframe$"blockord[2]"==2)
numberplace=j
stateplace=playframe[1,(795+j)]
responseplace=playframe[1,(232+j)]
addframe=data.frame(uid=uidplace,Bcorrinc=Bcorrincplace,Bfailinc=Bfailincplace,group=groupplace,cpresent=cpresentplace,block=blockplace, number=numberplace, state=stateplace, response=responseplace)
obsframe=rbind(obsframe,addframe)

}

}

dataframe=obsframe
dataframe$Aresponse=(dataframe$response==1)
dataframe$Bresponse=(dataframe$response==2)
dataframe$Cresponse=(dataframe$response==3)
dataframe$Cpresent=dataframe$cpresent
dataframe$version=dataframe$group
